package com.ljk.controller;

import com.ljk.entity.User;
import com.ljk.service.ExampleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * {@link RestController}  @Controller @ResponseBody的组合,并且不仅仅只有这些
 * ResponseBody 将该类返回到到页面
 * <p>
 * {@link Slf4j} lombok集成slf4j 产生的注解,用于日志
 * {@link RequestMapping} 可以加到类上也可以加到方法上加到类上再加到方法上就是两级地址,只加到方法上就只有一级地址
 *
 * @author leng
 * @date 2020/6/21 8:29
 */
@RestController
@Slf4j
public class IndexController {

    private ExampleService exampleService;

    @RequestMapping("index")
    public String index() {
        log.info("测试日志");
        return "Hello World,你好";
    }

    @RequestMapping("index2")
    public Map<String, String> index2() {
        Map<String, String> map = new HashMap<>(10);
        map.put("sss", "dsdd");
        return map;
    }

    @RequestMapping("index-mybatis")
    public User indexMybatis() {
        Map<String, String> map = new HashMap<>(10);
        User user = exampleService.getUser();
        return user;
    }
    @Autowired
    public void setExampleService(ExampleService exampleService) {
        this.exampleService = exampleService;
    }
}
